<?php
require '../include/library.inc.php';
require '../include/admin_login.inc.php';
	
$order_id = intval($_GET['order_id']);

	if ($order_id) {
		
		$sql = "SELECT
					order_id,
					order_date,
					firstname,
					lastname,
					email,
					country,
					continent,
					institution,
					status,
					note,
					price,
					paypal,
					iass,
					culinary,
					dinner,
					allergic,
					lang
					
				FROM
					orders
				WHERE
				    order_id ='$order_id'
					
					";
			$result_order = query($sql);
			$row = mysql_fetch_object($result_order);
		
		
		
		require '../languages/'.$row->lang.'.const.php';
		$pay_url = HTML_BASE.$row->lang.'/registration-form/'.base64_encode($order_id);
		
	$oredera = number_pad($order_id,5);
		
		if($_GET['status'] == '2')
		{
			
			
			$price = $row->price;
			$add = '';
				if($row->iass){
					
					$add .= __MESSAGE_IASS;
					
					if($row->continent == 3 && $row->country != 'ARGENTINA' && $row->country != 'VENEZUELA, BOLIVARIAN REPUBLIC OF')
						{
							$price -= 15;
						}else{
							$price -= 25;
						}
				}
				
				if($row->culinary){
					$price -= 35;
					$add .= __MESSAGE_Culinary;
				}
				
				if($row->dinner){
					$price -= 35;
					$add .= __MESSAGE_dinner;
				}
			
			
			
				mail( $row->email, 
					  sprintf(USER_ORDER_CONFIRM_SUBJECT, $oredera ),
					  sprintf(USER_ORDER_CONFIRM_MESSAGE,
					 $row->firstname, $row->lastname,
					  $oredera,$price, $add), 
					  HTML_HEADERS."From: Semio 2014 <".NO_REPLY_EMAIL.">");
			$sql = "UPDATE orders SET
				  
				  note = 'Изпратено известие за успешно плащане на ".date('d-m-Y H:i:s').'\n '.$row->note."'
				 
				 WHERE
				 order_id = '$order_id'
				";
			query($sql);
			
			$_SESSION['message'] = "Статус \"платена\" ";
	    
		}
		
		
		if($_GET['status'] != '2')
		{
			
		
			mail( $row->email, 
				  USER_ORDER_ERROR_SUBJECT,
				  sprintf(USER_ORDER_ERROR_MESSAGE,
				  $row->firstname, $row->lastname,
				  $pay_url,$pay_url,$oredera),
				  HTML_HEADERS."From: Semio 2014 <".NO_REPLY_EMAIL.">");
				  
				  
			$sql = "UPDATE orders SET
				  
				  note = 'Изпратено напомняне за плащане на ".date('d-m-Y H:i:s').'\n '.$row->note."'
				 
				 WHERE
				 order_id = '$order_id'
				";
			query($sql);
			
			$_SESSION['message'] = "Статус \"неплатена\" ";
		}
		
		
		$_SESSION['message'] .= "изпратен!";
	}
	redirect($_SERVER['HTTP_REFERER']);
?>